package com.itheima.controller;

/**
 * @author SWJ
 * @create 2021-08-12 22:14
 */

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;


/**
 * 体检检查项管理
 */
@RestController
//是直接让方法转化java对象转换jsion
@RequestMapping("/checkitem")
//  //res服务端返回结果
// axios.post("/checkitem/add.do", this.formData).then((res) => {
public class CheckItemController {
    @Resource
    //javax.annotation.Resource
    //作用相当于@Autowired，只不过@Autowired是byType自动注入，而@Resource默认byName自动注入。
    //区别：
    //@Reference注入的是分布式中的远程服务对象


    private CheckItemService checkItemService;
    //src/main/java/com/itheima/service/CheckItemService.java

    //新增检查项
    @RequestMapping("/add")
    //返回src/main/java/com/itheima/entity/Result.java

    //@RequestBod解析jsion提交数据
    public Result add(@RequestBody CheckItem checkItem) {
        try {
            checkItemService.add(checkItem);
            //新增的语句
        } catch (Exception e) {
            return new Result(false, MessageConstant.ADD_CHECKITEM_FAIL);
            //当检查项中是"新增检查项失败"
        }
        return new Result(true, MessageConstant.ADD_CHECKITEM_SUCCESS);
        //则新增检查项成功
    }

}

